package com.skyline.jfs.base.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import com.skyline.jfs.base.dao.AdminAdvanDao;
import com.skyline.jfs.base.model.Administrator;
import com.skyline.jfs.base.service.AdminAdvanService;


@Service("adminAdvanService")
public class AdminAdvanServiceImpl implements AdminAdvanService {

	@Autowired
	private AdminAdvanDao adminAdvanDao;
	
	public boolean modify(Integer id,Long jobNum, String firstName, String lastName,
			String department, String position, String phone, String email,
			String password, String passwordConfirm){
		if(password!=null&&password.equals(passwordConfirm)){
			System.out.println(password);
			if(!password.equals("")){
				password = String.valueOf(DigestUtils.md5DigestAsHex(password
						.getBytes()));
			}
			Administrator a= new Administrator();
			a.setId(id);
			a.setDepartment(department);
			a.setEmail(email);
			a.setFirstName(firstName);
			a.setJobNum(jobNum);
			a.setLastName(lastName);
			a.setPassword(password);
			a.setPhone(phone);
			a.setPosition(position);
			adminAdvanDao.update(a);
			return true;
		}
		else return false;
	}

	public void delete(Integer id){
		adminAdvanDao.delete(id);
	}
	
	public boolean add(Long jobNum, String firstName, String lastName,
			String department, String position, String phone, String email,
			String password, String passwordConfirm){
		if(password!=null&&password.equals(passwordConfirm)){
			password = String.valueOf(DigestUtils.md5DigestAsHex(password
					.getBytes()));
			Administrator a= new Administrator();
			a.setDepartment(department);
			a.setEmail(email);
			a.setFirstName(firstName);
			a.setJobNum(jobNum);
			a.setLastName(lastName);
			a.setPassword(password);
			a.setPhone(phone);
			a.setPosition(position);
			adminAdvanDao.insertAdmin(a);
			return true;
		}
		else return false;
	}

}
